////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                           BailterRay                                       //
//                    Pip Robbins & Zhao Zhang                                //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
class BailterRaySadBot extends UTBot;

var bool bStarted;
var vector StartLoc;
var rotator LastRotation;
var BailterRayPawn PC;
var bool bFrozen;
var bool bFirstShieldSound;
var bool bSecondShieldSound;
var bool bThirdShieldSound;
var SoundCue HealSound;
var SoundCue ShieldChangeSound;
var SoundCue ShieldDeactivated;
var ParticleSystem HealEffect;
var ParticleSystem ShieldChangeEffect;
var ParticleSystem ShieldActiveEffect;
var ParticleSystemComponent PSC;

const RECHARGE_HEALTH_TIME            = 12; // Time till self heal!

function rotator GetAdjustedAimFor(Weapon W, vector StartFireLoc)
{
	return Rotation;
}

function Initialize(float InSkill, const out CharacterInfo BotInfo)
{
	local UTPlayerReplicationInfo CPRI;
	local CustomCharData MyBotCharData;

	// copy visual properties
	CPRI = UTPlayerReplicationInfo(PlayerReplicationInfo);
    MyBotCharData = (class'UTCustomChar_Data'.static.CharDataFromString("EvilRobot,EVRB,evilRobot_head,NONE,NONE,NONE,evilRobot_torso,NONE,evilRobot_arms,evilRobot_thighs,evilRobot_boots,F,F"));
	super.Initialize(InSkill, BotInfo);

	CPRI.SetCharacterData(MyBotCharData);


}

event Tick( float DeltaTime )
{
    if(PSC.bIsActive){
       PSC.SetTranslation(Pawn.Location);
    }

    forEach VisibleCollidingActors(class'BailterRayPawn', PC, 1900)
    {
        if(PC.IsHumanControlled())
            break;
    }

    if(PC != none)
    {
        if((Abs(Pawn.Location.X - PC.Location.X)) < 750 && PC.IsHumanControlled())
        {
            GotoState('FrozenMovement');
            Focus = PC;
            FireWeaponAt(PC);
        }
    }
}

simulated function GotoFrozen()
{
    bFrozen = true;
}

function bool FireWeaponAt(Actor A)
{
	if ( A == None )
		A = Enemy;
	if ( (A == None) || (Focus != A) )
		return false;
	Focus = A;

    return WeaponFireAgain(false);
}

function RechargeHealth()
{
    Pawn.Health = Pawn.HealthMax;
    bFirstShieldSound = false;
    bSecondShieldSound = false;
    bThirdShieldSound = false;
    if(HealEffect != None)
	{
	    PSC.SetActive(false);
		PSC = WorldInfo.MyEmitterPool.SpawnEmitter(HealEffect, Pawn.Location, Pawn.Rotation);
		PSC.SetScale(0.75);
		Pawn.AttachComponent(PSC);
	}

	if(HealSound != None)
    {
        HealSound.VolumeMultiplier = 2.0;
	    PlaySound(HealSound, true);
    }
}

function NotifyTakeHit(Controller InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum)
{
    if(Damage >= Pawn.Health){
       PSC.SetActive(false);
    }

    if(Pawn.health > Pawn.HealthMax / 2){
        if(ShieldActiveEffect != None)
    	{
            PSC.SetActive(false);
    		PSC = WorldInfo.MyEmitterPool.SpawnEmitter(ShieldActiveEffect, Pawn.Location + vect(0,0, -20), Pawn.Rotation);
    		PSC.SetScale(0.75);
    	}
    	if(!bFirstShieldSound)
        {
	       setTimer(RECHARGE_HEALTH_TIME, false, 'RechargeHealth');
        }
   	    if(ShieldChangeSound != None && !bFirstShieldSound)
	    {
	      bFirstShieldSound=true;
	      ShieldChangeSound.VolumeMultiplier = 2.0;
	 	  PlaySound(ShieldChangeSound, true);
	    }
	    Pawn.Weapon.FireInterval[0]= 2.0;
        Pawn.Weapon.WeaponProjectiles[0] = class'BailterRayProj_EvilRay';
   	}

    if(Pawn.health < Pawn.HealthMax / 2 && Pawn.health > 40){
        if(ShieldActiveEffect != None)
    	{
    	    PSC.SetActive(false);
    		PSC = WorldInfo.MyEmitterPool.SpawnEmitter(ShieldChangeEffect, Pawn.Location + vect(0,0, -20), Pawn.Rotation);
    		PSC.SetScale(0.75);
   	    }
   	    if(ShieldChangeSound != None && !bSecondShieldSound)
	    {
	      bSecondShieldSound=true;
	      ShieldChangeSound.VolumeMultiplier = 2.0;
	 	  PlaySound(ShieldChangeSound, true);
	    }
   	    Pawn.Weapon.FireInterval[0]= 1.0;
        Pawn.Weapon.WeaponProjectiles[0] = class'BailterRay.BailterRayProj_RedRay';
	}
	if(Pawn.health < 40 && Pawn.health > 0){
        if(ShieldDeactivated != None && !bThirdShieldSound)
	    {
          bThirdShieldSound=true;
	      ShieldDeactivated.VolumeMultiplier = 2.0;
	 	  PlaySound(ShieldDeactivated, true);
	    }
        PSC.SetActive(false);
	}

	LastUnderFire = WorldInfo.TimeSeconds;
	if ( (instigatedBy != None) && (instigatedBy != self) )
		damageAttitudeTo(instigatedBy, Damage);
}

state Dead
{
	function BeginState(Name PreviousStateName)
	{
	   if(PSC != none){
           PSC.SetActive(false);
       }
       super.BeginState(previousStateName);
	}


}

defaultproperties
{
    ScriptedFireMode=0
    bFrozen=false
    bFirstShieldSound=false
    bSecondShieldSound=false
    bThirdShieldSound=false

    HealEffect=ParticleSystem'WP_Translocator.Particles.P_WP_Translocator_Teleport'
    ShieldChangeEffect=ParticleSystem'BlueSadRobot.Effects.RedShield'
    ShieldActiveEffect=ParticleSystem'BlueSadRobot.Effects.BlueShield'

    HealSound=SoundCue'A_Pickups.Health.Cue.A_Pickups_Health_Super_Cue'
    ShieldChangeSound=SoundCue'A_Vehicle_Paladin.SoundCues.A_Vehicle_Paladin_ShieldActivate'
    ShieldDeactivated=SoundCue'A_Vehicle_Paladin.SoundCues.A_Vehicle_Paladin_ShieldOff'
}
